package com.totoro.metrics;

import com.codahale.metrics.Histogram;
import com.codahale.metrics.MetricRegistry;

import java.util.Random;

/**
 * Histogram可以为数据流提供统计数据。 除了最大值，最小值，平均值外，它还可以测量 中值(median)，百分比比如XX%
 * Created by Niki on 2018/8/28 14:44
 */
public class HistogramDemo {
    private static final MetricRegistry metrics = new MetricRegistry();

    private static Histogram histogram = metrics.histogram(MetricRegistry.name(HistogramDemo.class, "response-size"));
    private static Random random = new Random(2);

    private static void handleRequest() {
        histogram.update(random.nextInt());
    }


    public static void main(String[] args) throws InterruptedException {
        OutputUtil.console(metrics);

        int i = 0;

        while (i < 100) {
            i++;
            handleRequest();
            Thread.sleep(100);
        }
    }
}
